#region Using Statements
using System;
using System.IO;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
#endregion

namespace SkyBurner
{
    public class BitmapFont : BaseObject
    {
        int m_nFontSize;
        private Texture2D m_bitmapFontLetters;
        private Texture2D m_bitmapFontNumbers;

        public BitmapFont(BaseGame game, String pBitmapFontLetters, String pBitmapFontNumbers, int pFontSize)
            : base(game)
        {
            m_nFontSize = pFontSize;
            m_bitmapFontLetters = m_Game.ContentManager.Load<Texture2D>(pBitmapFontLetters);
            m_bitmapFontNumbers = m_Game.ContentManager.Load<Texture2D>(pBitmapFontNumbers);
        }

        public void Print(int X, int Y, String pMessage, int pSize)
        {
            char[] s = pMessage.ToUpper().ToCharArray();

            m_Game.SpriteBatch.Begin();
            for (int i = 0; i < s.Length; i++)
            {
                if ((s[i] >= 'A') && (s[i] <= 'Z'))
                {
                    int fontX = s[i] - 'A';
                    Rectangle rectSource = new Rectangle(fontX * m_nFontSize, 0, m_nFontSize, m_nFontSize);
                    Rectangle rectDest = new Rectangle(X + i * (pSize + 1), Y, pSize, pSize);

                    m_Game.SpriteBatch.Draw(m_bitmapFontLetters, rectDest, rectSource, Color.White);
                }
                else if (((s[i] >= '0') && (s[i] <= '9')) || s[i] == '.')
                {
                    int fontX;
                    if (s[i] == '.')
                        fontX = 10;
                    else
                        fontX = s[i] - '0';

                    Rectangle rectSource = new Rectangle(fontX * m_nFontSize, 0, m_nFontSize, m_nFontSize);
                    Rectangle rectDest = new Rectangle(X + i * (pSize + 1), Y, pSize, pSize);

                    m_Game.SpriteBatch.Draw(m_bitmapFontNumbers, rectDest, rectSource, Color.White);
                }
            }
            m_Game.SpriteBatch.End();
        }

        public void PrintCenterX(int Y, String pMessage, int pSize)
        {
            int nPosX = (m_Game.GraphicsDevice.Viewport.Width - (pMessage.Length * (pSize + 1))) / 2;
            Print(nPosX, Y, pMessage, pSize);
        }
    }
}
